#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#include"variables.h"
#include"fonctions.h"



		/**********************About - Reader File**********************/
char * version_read (char * found)
{
	int cpt=0;
	while (found[cpt]!='(')
	{
		cpt++;
	}
	char * version=(char *)calloc(cpt-1, sizeof(char));
	strncpy(version, found, cpt-1);
	return version;
	free(version);
}

void os_read(char * buffer, data * ptr)
{
	char * found=NULL;
	found=strstr(buffer, "Linux");
	if (found!=NULL)
	{
		ptr->os_machine="Linux";
		ptr->os_version=version_read(found);
	}
	else if ((found=strstr(buffer,"Windows"))!=NULL)
	{
		ptr->os_machine="Windows";

		ptr->os_version=version_read(found);
	}
	else if ((found=strstr(buffer, "Mac"))!=NULL)
	{
		ptr->os_machine="MAC-OS";
		ptr->os_version=version_read(found);
	}
	else
	{
		printf ("------------\n");
		printf ("UNKNOWN OS\n");
		printf ("------------\n");
	}
	

}

void NAT_read(char * buffer, data * ptr)
{
	char * found=NULL;
	found=strstr(buffer, "NAT");
	if (found!=NULL)
	{
//		printf ("Le Hacker passe par une NAT!\n");
		ptr->NAT=1;
	}
}

void fw_read(char * buffer, data * ptr)
{
	char * found=NULL;
	found=strstr(buffer, "firewall");
	if (found!=NULL)
	{
//		printf ("Le Hacker utilise un Firewall!\n");
		ptr->firewall=1;
	}
}

void distance_read (char * buffer, data * ptr)
{
	char *  found=NULL;
	found=strstr(buffer,"distance");
	if (found!=NULL)
	{
		found=found+9;
		ptr->distance=atoi(found);
	}
}

void up_read (char * buffer, data * ptr)
{
	char *  found=NULL;
	found=strstr(buffer,"up");
	if (found!=NULL)
	{
		found=found+4;
		ptr->uptime=atoi(found);
	}
}


void link_read (char * buffer, data * ptr)
{
        char *chaine;
        chaine=strstr(buffer,"link");
	if (chaine!=NULL)
	{
		chaine=chaine+6;
		int i=0;
		i=strlen(chaine)-2;
		ptr->link_type=(char *)calloc(i,sizeof(char));
		strncpy(ptr->link_type,chaine,i);
	}
}

